﻿<Window x:Class="iPlayMVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cp="clr-namespace:DropDownCustomColorPicker;assembly=CustomColorPicker"
        Title="iPlay" Height="270" Width="740" 
        xmlns:local="clr-namespace:iPlayMVVM;assembly=" Topmost="{Binding ElementName=AlwaysOnTop, Path=IsChecked}"
        xmlns:viewmodel="clr-namespace:iPlayMVVM.ViewModel;assembly=" ResizeMode="CanResizeWithGrip" 
        Icon="/iPlayMVVM;component/Resources/PerfCenterCpl.ico" MinWidth="600" MinHeight="270">
    <Window.Resources>
        <local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <local:BooleanToStringConverter x:Key="BooleanToStringConverter"/>
        <local:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
        <local:CommaStringToListConverter x:Key="CommaStringToListConverter"/>
        <local:ListToCountConverter x:Key="ListToCountConverter"/>
        <local:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
        <local:TextToVisibilityConverter x:Key="TextToVisibilityConverter"/>
        <local:BlacklistValidator x:Key="BlacklistValidator"/>
        <local:NonZeroToVisibilityConverter x:Key="NonZeroToVisibilityConverter"/>
        <local:BooleanToPlayStateConverter x:Key="BooleanToPlayStateConverter"/>
        <local:BooleanToPlayStateIconConverter x:Key="BooleanToPlayStateIconConverter"/>
        <local:SongsNumberToStringConverter x:Key="SongsNumberToStringConverter"/>
        <local:HeightConverter x:Key="HeightConverter"/>
        <local:HeightConverter2 x:Key="HeightConverter2"/>
        <local:ProgressBarConverter x:Key="ProgressBarConverter"/>
        <!--<local:BooleanToProgressStateConverter x:Key="BooleanToProgressStateConverter"/>-->
        <viewmodel:iTunesViewModel x:Key="iTunesViewModel"/>
        <LinearGradientBrush x:Key="Background" EndPoint="1,1" StartPoint="-.25,0">
            <GradientStop Color="{Binding ElementName=customCP1, Path=SelectedColor}" Offset="0" />
            <GradientStop Color="{Binding ElementName=customCP2, Path=SelectedColor}" Offset="1" />
        </LinearGradientBrush>
        
    </Window.Resources>
    <Window.DataContext>
        <viewmodel:iTunesViewModel/>
    </Window.DataContext>
    
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo Description="My Taskbar Sample" ProgressState="Normal" >
            <TaskbarItemInfo.ProgressValue>
                <MultiBinding Converter="{StaticResource ProgressBarConverter}">
                    <Binding Path="SongsUsed" Mode="OneWay" Converter="{StaticResource ListToCountConverter}"/>
                    <Binding Path="NumberOfSongs"/>
                </MultiBinding>
            </TaskbarItemInfo.ProgressValue>
            <TaskbarItemInfo.ThumbButtonInfos>
                <ThumbButtonInfoCollection>
                    <ThumbButtonInfo x:Name="_ThumbnailBackButton" 
                                     Description="Previous" 
                                     ImageSource="Resources\Backward.ico" 
                                     Command="{Binding BackTrack}"/>
                    <ThumbButtonInfo x:Name="_ThumbnailPauseButton" Description="Pause" 
                                     ImageSource="{Binding Path=PlayState, 
                                     Converter={StaticResource BooleanToPlayStateIconConverter}}" 
                                     DismissWhenClicked="False"
                                     Command="{Binding PlayPause}"/>
                    <ThumbButtonInfo x:Name="_ThumbnailForwardButton" 
                                     Description="Next" 
                                     ImageSource="Resources\Forward.ico" 
                                     Command="{Binding ForwardTrack}"/>
                </ThumbButtonInfoCollection>
            </TaskbarItemInfo.ThumbButtonInfos>
        </TaskbarItemInfo>
    </Window.TaskbarItemInfo>
    
    <Grid Background="{StaticResource Background}">
        <!-- Tab Control -->        
        <TabControl Name="tabControl1" Margin="10" Style="{DynamicResource SimpleTabControl}" >
            <!-- Source Playlist-->    
            <TabItem Header="Source Playlist" Name="tabItem1" IsEnabled="{Binding Path=IsIdle}" IsSelected="{Binding Path=IsIdle, Mode=OneWay}" Style="{DynamicResource SimpleTabItem}">
                <Grid Background="{StaticResource Background}">
                    <StackPanel Margin="5">
                        <!-- Dock Panel for Playlist Combo Box and Buttons-->
                        <DockPanel Margin="0,5" Height="25">
                            <ComboBox DisplayMemberPath="Name" HorizontalAlignment="Left" Margin="2,0" ItemsSource="{Binding Path=Playlists}" Name="cmbPlaylists" SelectedIndex="0" SelectedItem="{Binding Path=SelectedPlaylist}" Width="290" Style="{DynamicResource SimpleComboBox}" />
                            <Button Command="{Binding Path=LoadPlaylistsCommand}" Content="Refresh" HorizontalAlignment="Left" Margin="2,0" Name="LoadButton" Width="75"  ToolTip="Refresh Playlists from iTunes"/>
                        </DockPanel>
                        <Grid Name="ParentGrid">
                            <Expander Header="Songs" Name="SongsExpander" ExpandDirection="Left" ToolTip="Click to show or hide the songs in the selected playlist">
                                <DataGrid ItemsSource="{Binding Path=Tracks, IsAsync=True}" AutoGenerateColumns="False" Height="{Binding ElementName=tabControl1, Path=ActualHeight, Converter={StaticResource HeightConverter}}" 
                                      HorizontalAlignment="Left" Name="dataGrid2" GridLinesVisibility="Vertical" 
                                      CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserDeleteRows="False" IsReadOnly="True" CanUserResizeRows="False"
                                      AlternatingRowBackground="{StaticResource Background}">
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Header="Song" Width="*" Binding="{Binding Name}" />
                                        <DataGridTextColumn Header="Artist"  Width="*" Binding="{Binding Artist}" />
                                        <DataGridTextColumn Header="Album" Width="*" Binding="{Binding Album}" />
                                    </DataGrid.Columns>
                                </DataGrid>
                            </Expander>
                            <GroupBox Header="Options" HorizontalAlignment="Left" Name="groupBox1" Visibility="{Binding ElementName=SongsExpander, Path=IsExpanded, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
                                <Grid>
                                    <DockPanel Margin="5">
                                        <Border BorderBrush="White" BorderThickness="2">
                                            <StackPanel Margin="5">
                                                <DockPanel Margin="5,1,0,-5" HorizontalAlignment="Left">
                                                    <Label Content="Artists To " HorizontalAlignment="Left" Name="label1" />
                                                    <ComboBox HorizontalAlignment="Left" SelectedIndex="{Binding BlackOrWhiteList, Mode=OneWayToSource}" Margin="0,3" Style="{DynamicResource SimpleComboBox}" >
                                                        <ComboBox.Items>
                                                            <ComboBoxItem Name="BlackList" Content="BlackList"/>
                                                            <ComboBoxItem Name="ChooseFrom" Content="Choose From"/>
                                                        </ComboBox.Items>
                                                    </ComboBox>
                                                    <Label Content="(comma separated list)" HorizontalAlignment="Left"/>
                                                </DockPanel>
                                                <TextBox Height="25" HorizontalAlignment="Left" Margin="5" Name="textBox1" Width="250" Text="{Binding Path=BlacklistArtists, Converter={StaticResource CommaStringToListConverter}}"  />
                                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                                    <RadioButton Content="By Substring" Margin="3"  Name="radioButton1"  Visibility="{Binding ElementName=textBox1, Path=Text, Converter={StaticResource TextToVisibilityConverter}, Mode=OneWay}" IsChecked="{Binding Path= Substring, Mode=TwoWay}"/>
                                                    <RadioButton Content="By Exact Match" Margin="3"  Name="radioButton2"  Visibility="{Binding ElementName=textBox1, Path=Text, Converter={StaticResource TextToVisibilityConverter}, Mode=OneWay}" IsChecked="{Binding Path= Substring, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}"/>
                                                </StackPanel>
                                            </StackPanel>
                                        </Border>
                                        <Border BorderBrush="White" BorderThickness="0,2,2,2">
                                            <StackPanel Margin="5">
                                                <Label Content="Number of Songs"  HorizontalAlignment="Left" Name="label2"  />
                                                <Slider Height="23" HorizontalAlignment="Left" Name="slider1" Margin="5" Width="250"  SmallChange="1" Minimum="1" 
                                                Maximum="{Binding Path=Tracks, Converter={StaticResource ListToCountConverter}, Mode=TwoWay}" IsSnapToTickEnabled="True" AutoToolTipPlacement="BottomRight"
                                                Value="{Binding Path= NumberOfSongs, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Interval="10" IsMoveToPointEnabled="True" ToolTip="Fine Tune With Arrow Keys" Style="{DynamicResource SimpleSlider}"/>
                                                <Label Content="{Binding ElementName=slider1, Path=Value, Converter={StaticResource SongsNumberToStringConverter}}" HorizontalAlignment="Center" />
                                            </StackPanel>
                                        </Border>
                                    </DockPanel>
                                    <!--<Label Content="{Binding ElementName=textBox1, Path=Validation.Errors[0].ErrorContent}" Height="28" HorizontalAlignment="Left" Margin="128,52,0,0" Name="label7" VerticalAlignment="Top" Width="130" />-->
                                </Grid>
                            </GroupBox>
                        </Grid>
                    </StackPanel>
                </Grid>
            </TabItem>
            <!-- Playlist Settings -->
            <TabItem Header="Playlist Settings" Name="tabItem2" IsEnabled="{Binding Path=IsIdle}" Style="{DynamicResource SimpleTabItem}">
                <Grid Background="{StaticResource Background}">
                    <StackPanel Margin="5">
                        <GroupBox  Header="Playlist Title" HorizontalAlignment="Left" Name="playlistName">
                            <DockPanel>
                                <TextBox  Height="24" Name="PlaylistName" Text="{Binding Path= PlaylistName}"  Width="337" Margin="5" HorizontalAlignment="Left"  />
                                <CheckBox Content="Overwrite" Name="chbOverwrite"  IsChecked="{Binding Path= OverWrite}" VerticalAlignment="Center" HorizontalAlignment="Left"  Width="80" />
                            </DockPanel>
                        </GroupBox>
                        <DockPanel>
                            <GroupBox Header="Refresh"  HorizontalAlignment="Left"  Name="groupBox2" VerticalAlignment="Top" ToolTip="Check to not use any that were used last time.">
                                <DockPanel>
                                    <CheckBox Content="Songs" HorizontalAlignment="Left" Margin="5" IsChecked="{Binding Path=RefreshSongs, Mode=OneWayToSource}" Name="chbRefreshSongs"  />
                                    <CheckBox Content="+Artists" HorizontalAlignment="Left" Margin="5" IsChecked="{Binding Path=RefreshArtists, Mode=OneWayToSource}"  Name="chbRefreshArtists" />
                                </DockPanel>
                            </GroupBox>
                            <CheckBox Content="No Duplicate Artists" VerticalAlignment="Center"  HorizontalAlignment="Left" Margin="5" Name="checkBox1" IsChecked="{Binding Path= NoDuplicates}" />
                            <TextBlock Visibility="Hidden" Text="Like the app? Need help? Contact me at xander.dumaine@gmail.com"  HorizontalAlignment="Right" VerticalAlignment="Center" Margin="20,0" Name="label6" TextWrapping="Wrap" />
                        </DockPanel>
                    </StackPanel>
                </Grid>
            </TabItem>
            <!-- Now Playing -->
            <TabItem Header="Now Playing" Style="{DynamicResource SimpleTabItem}" >
                <TabItem.InputBindings>
                    <KeyBinding Command="{Binding PlayPause}" Gesture="SPACE"/>
                    <KeyBinding Command="{Binding ForwardTrack}" Gesture="RIGHT"/>
                    <KeyBinding Command="{Binding BackTrack}" Gesture="LEFT"/>
                </TabItem.InputBindings>
                <Grid Background="{StaticResource Background}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="TextColumn" MinWidth="500"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <!-- Dock Panel For Controls, Titles and Image-->
                    <!--<DockPanel Margin="5">-->
                        <!-- Stack Panel Includes Controls and Titles -->
                    <StackPanel Margin="0,0,5,0">
                        <!-- Dock Panel For Controls -->
                        <DockPanel>
                            <Button Command="{Binding BackTrack}" Background="#00000000" Content="&lt;&lt;" Height="23" HorizontalAlignment="Left"  Name="button3" VerticalAlignment="Top" Width="42" Focusable="False" />
                            <Button Command="{Binding PlayPause}" Background="#00000000" Content="{Binding Path=PlayState, Converter={StaticResource BooleanToPlayStateConverter}}" Height="23" HorizontalAlignment="Left" Name="button5" VerticalAlignment="Top" Width="42" Focusable="False" />
                            <Button Command="{Binding ForwardTrack}" Background="#00000000" Content="&gt;&gt;" Height="23" HorizontalAlignment="Left"  Name="button4" VerticalAlignment="Top" Width="42" Focusable="False" />
                            <Slider Height="18" HorizontalAlignment="Left"  Name="slider2" VerticalAlignment="Top" Width="360" Margin="5,5,0,0"
                            Maximum="{Binding TrackDuration}" Value="{Binding Path=PlayerPosition, Mode=OneWay}" IsManipulationEnabled="False" IsMoveToPointEnabled="True" Focusable="False" Style="{DynamicResource SimpleSlider}" />
                        </DockPanel>
                        <Viewbox Width="{Binding ElementName=TextWidth, Path=ActualWidth}" Height="{Binding ElementName=tabControl1, Path=ActualHeight, Converter={StaticResource HeightConverter2}}">
                            <Label FontFamily="Eras ITC" Content="{Binding Path=CurrentSong.Name}" FontStyle="Italic" HorizontalAlignment="Left" MaxWidth="Infinity" Margin="0,0,0,-5" />
                        </Viewbox>
                        <Viewbox Width="{Binding ElementName=TextWidth, Path=ActualWidth}" Height="{Binding ElementName=tabControl1, Path=ActualHeight, Converter={StaticResource HeightConverter2}}">
                            <Label Content="{Binding Path=CurrentSong.Artist}" FontFamily="Eras ITC" HorizontalAlignment="Right" FontWeight="Normal" FontStyle="Normal" Margin="0,-5" />
                        </Viewbox>
                    </StackPanel>
                    <GridSplitter Width="4" Grid.Column="0"/>
                        <Image Grid.Column="1" Name="AlbumArt" Source="{Binding Path=ArtworkPath}" HorizontalAlignment="Center" DockPanel.Dock="Right" />
                    <!--</DockPanel>-->
                </Grid>
            </TabItem>
            <!-- Loading -->
            <TabItem Header="Tools" Style="{DynamicResource SimpleTabItem}" BorderBrush="Transparent">
                <Grid Background="{StaticResource Background}">
                    <StackPanel>
                        <GroupBox Header="App Settings" HorizontalAlignment="Left" Width="Auto" Margin="5,5,0,0">
                            <DockPanel>
                                <Border BorderBrush="White" BorderThickness="2" Margin="5,5,0,5">
                                    <StackPanel Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Center"  Margin="5">
                                        <DockPanel>
                                            <Label Content="Gradient Color 1:"/>
                                            <cp:CustomColorPicker DataContext="{Binding}" SelectedColor="{Binding Path=GradientColor1, Mode=TwoWay}" Width="40" Name="customCP1" VerticalAlignment="Center" Margin="5,0"/>
                                        </DockPanel>
                                        <DockPanel Margin="0,5,0,0">
                                            <Label Content="Gradient Color 2:"/>
                                            <cp:CustomColorPicker DataContext="{Binding}" SelectedColor="{Binding Path=GradientColor2, Mode=TwoWay}" Width="40" Name="customCP2" VerticalAlignment="Center" Margin="5,0"/>
                                        </DockPanel>
                                    </StackPanel>
                                </Border>
                                <Border BorderBrush="White" BorderThickness="0,2,2,2" Margin="0,5,0,5">
                                    <StackPanel VerticalAlignment="Center">
                                        <CheckBox Name="AlwaysOnTop" Content="Always on Top" IsChecked="{Binding Path=AlwaysOnTop, Mode=TwoWay}" Margin="5"/>
                                        <CheckBox Name="SavePlaylistName" Content="Save Custom Playlist Name" ToolTip="Uncheck to autogenerate." IsChecked="{Binding Path=SavePlaylistName}" Margin="5"/>
                                    </StackPanel>
                                </Border>
                                <Border BorderBrush="White" BorderThickness="0,2,2,2" Margin="0,5,5,5">
                                    <StackPanel VerticalAlignment="Center">
                                        <CheckBox Name="QuickGenerate" Content="Quick Generate on Startup" IsChecked="{Binding Path=QuickGenerate, Mode=TwoWay}" Margin="5"/>
                                        <TextBlock Text="For number of songs, use the slider on the Source Playlist Tab, then Save the settings" FontSize="10" Width="190" TextWrapping="Wrap" Margin="5,-5,5,5"/>
                                        <CheckBox Visibility="Hidden" Name="NewOption" Content="New Option" ToolTip="Uncheck to autogenerate." IsChecked="{Binding Path=SavePlaylistName}" Margin="5"/>
                                    </StackPanel>
                                </Border>
                            </DockPanel>
                        </GroupBox>
                    </StackPanel>
                    <Expander Header="Save Settings" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5">
                        <StackPanel>
                            <Button Content="Save This Page" Command="{Binding Path=SaveAppSettingsCommand}" Width="100" Height="25" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Top"/>
                            <Button Content="Save All Settings" Command="{Binding Path=SaveSettingsCommand}" Width="100" Height="25" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Top"/>
                        </StackPanel>
                    </Expander>
                </Grid>
            </TabItem>
            <TabItem Style="{DynamicResource SimpleTabItem}" Header="Loading" Name="tabItem3" Visibility="{Binding Path= IsIdle, Converter={StaticResource InverseBooleanToVisibilityConverter}}" IsSelected="{Binding Path= IsIdle, Converter= {StaticResource InverseBooleanConverter}, Mode=OneWay}">
                <Grid Background="{StaticResource Background}">
                    <StackPanel Margin="5">
                        <Grid Height="30">
                            <ProgressBar Name="progressBar1" 
                                 Maximum="{Binding Path=NumberOfSongs}" 
                                 Value="{Binding Path= SongsUsed, Mode=OneWay, Converter={StaticResource ListToCountConverter}}" 
                                 Foreground="#FF19DD0A" Style="{DynamicResource SimpleProgressBar}" />
                            <!-- Stack Panel For Progress Bar Labels -->
                            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                                <Label Content="{Binding Path=SongsUsed, Converter={StaticResource ListToCountConverter}}" HorizontalAlignment="Center" Margin="10,0" Name="label4" />
                                <Label Content="of" HorizontalAlignment="Center"  Name="label5"  />
                                <Label Content="{Binding Path=NumberOfSongs}" HorizontalAlignment="Center" Margin="10,0" Name="label3"  />
                            </StackPanel>
                            <Button Content="Play It!" Command="{Binding Path=PlayCommand}" HorizontalAlignment="Right" Name="button2"  Width="124" Background="#00000000" Cursor="ScrollE" 
                            Visibility="{Binding Path=SongsUsed, Converter={StaticResource NonZeroToVisibilityConverter}, Mode=OneWay}" ToolTip="Play First Song of Playlist" BorderBrush="{x:Null}" />
                        </Grid>
                        <DataGrid ItemsSource="{Binding Path=SongsUsed}" AutoGenerateColumns="False" Height="{Binding ElementName=tabControl1, Path=ActualHeight, Converter={StaticResource HeightConverter}}" HorizontalAlignment="Left" Margin="0,5" Name="dataGrid1" 
                                  CanUserReorderColumns="False" VerticalAlignment="Top" CanUserResizeColumns="False" CanUserResizeRows="False" GridLinesVisibility="Vertical" 
                                  IsReadOnly="True" AlternatingRowBackground="{StaticResource Background}">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Song" Width="*" Binding="{Binding Name}" />
                                <DataGridTextColumn Header="Artist"  Width="*" Binding="{Binding Artist}" />
                                <DataGridTextColumn Header="Album" Width="*" Binding="{Binding Album}" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </StackPanel>
                </Grid>
            </TabItem>
        </TabControl>
        <!-- Dock Panel For Global Buttons (outside of tab controls) -->
        <DockPanel Height="35" Width="175" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,0">
            <Button Content="{Binding Path= ButtonMessage}" Command="{Binding Path= ExecuteCommand}" Margin="1,5" HorizontalAlignment="Right" DockPanel.Dock="Right" Name="btnExecute" Width="75" />
            <Button Content="FullScreen" Command="{Binding FullScreenCommand}" Margin="1,5" HorizontalAlignment="Right" DockPanel.Dock="Right" Name="button6" Width="75" />
        </DockPanel>
    </Grid>
</Window>
